diff --git a/2016/event.php b/2016/event.php index cb54677..e7a7d4b 100644 --- a/2016/event.php +++ b/2016/event.php @@ -1,352 +1,352 @@ . require 'load.php'; $conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) ->queryRow(); $conference or die_with_404(); $event = FullEvent::factoryByConferenceAndUID( $conference->getConferenceID(), @ $_GET['uid'] )->queryRow(); $event or die_with_404(); FORCE_PERMALINK and $event->forceEventPermalink(); $args = [ 'title' => sprintf( __("%s: %s"), $event->getChapterName(), $event->getEventTitle() ), - 'url' => $event->getEventURL() + 'url' => $event->getEventURL( true ), ]; if( $event->hasEventImage() ) { $args['og'] = [ - 'image' => $event->getEventImage() + 'image' => $event->getEventImage( true ), ]; } // Adding subscribers $subscribed = null; if( isset( $_POST['subscription_email'] ) && $event->areEventSubscriptionsAvailable() ) { $email = $_POST['subscription_email']; if( filter_var($email, FILTER_VALIDATE_EMAIL) ) { $event->addSubscription($email); $args['alert'] = __("Grazie per esserti iscritto."); $args['alert.type'] = Messagebox::INFO; $subscribed = true; } else { $args['alert'] = __("E-mail non valida."); $args['alert.type'] = Messagebox::ERROR; $subscribed = false; } } Header::spawn( null, $args ); ?> isEventEditable() ): ?>

getFullEventEditURL(), __("Modifica evento") . icon('edit', 'left') ) ?>

<?php
 						echo esc_attr( $event->getEventTitle() )
 					?>
getTrackName() ?>
getTrackLabel() ?>
getRoomName() ?>
@ getLocationGeoOSM(), $conference->getLocationName(), $conference->getLocationAddress(), null, 'target="_blank"' ) ?>
getLocationAddress() ?>
getEventHumanStart() ?>
getEventStart('d/m/Y'), $event->getEventStart('H:i') ) ?>
getEventCalURL(), __( "Scarica promemoria calendario" ) ) ?>
hasEventAbstract() ): ?>

getEventAbstractHTML( ['p' => 'flow-text'] ) ?>
hasEventDescription() ): ?>

getEventDescriptionHTML( ['p' => 'flow-text'] ) ?>
areEventSubscriptionsAvailable() ): ?>

hasEventNote() ): ?>

getEventNoteHTML( ['p' => 'flow-text'] ) ?>
factorySharebleByEvent() ->queryGenerator(); ?> valid() ): ?>

isSharableDownloadable() ): ?>

getSharablePath(), icon('attachment', 'left') . $sharable->getSharableTitle(['prop' => true]), null, null, 'target="_blank"' ), $sharable->getSharableLicense()->getLink() ) ?>

isSharableVideo() ): ?>

getSharablePath(), icon('share', 'left') . $sharable->getSharableTitle( ['prop' => true] ), null, null, 'target="_blank"' ), $sharable->getSharableLicense()->getLink() ) ?>

factoryUserByEvent() ->queryGenerator(); ?> valid() ): ?>
getUserURL(), "

{$user->getUserFullname()}

", sprintf( __("Profilo di %s"), $user->getUserFullname() ), 'valign' ) ?>

factoryPreviousFullEvent() ->select('event_uid', 'event_title', 'chapter_uid', 'conference_uid', 'event_start') ->limit(1) ->queryRow(); $next = $event->factoryNextFullEvent() ->select('event_uid', 'event_title', 'chapter_uid', 'conference_uid', 'event_start') ->limit(1) ->queryRow(); ?>

getEventURL( ROOT ), $previous->getEventTitle() ) ?>

getEventURL( ROOT ), $next->getEventTitle() ) ?>

. /* * This is the Linux Day Torino Tropical (trop-iCal) API * * It print a (hopefully) valid iCal file of a Linux Day Torino event. */ // load the framework require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'load.php'; // die if missing Conference UIR if( empty( $_GET['conference'] ) ) { http_response_code( 404 ); die( "Missing 'conference' argument" ); } $event = null; $conference = FullConference::factoryFromUID( $_GET['conference'] ) ->queryRow(); // die if missing Conference if( !$conference ) { http_response_code( 404 ); die( "Conference not found" ); } // die if missing Event UID if( isset( $_GET['event'] ) ) { $event = FullEvent::factoryFromConferenceAndEventUID( $conference, $_GET['event'] ) ->queryRow(); if( !$event ) { http_response_code( 404 ); die( "Event not found" ); } } $event_url = null; if( $event ) { $event_ID = $event->getEventID(); $event_title = $event->getEventTitle(); $event_start = $event->getEventStart(); $event_end = $event->getEventEnd(); $event_desc = $event->getEventDescription(); if( $event->hasEventPermalink() ) { - $event_url = $event->getEventURL(); + $event_url = $event->getEventURL( true ); } } else { $event_ID = $conference->getConferenceID(); $event_title = $conference->getConferenceTitle(); $event_url = $conference->getConferenceURL(); $event_start = $conference->getConferenceStart(); $event_end = $conference->getConferenceEnd(); $event_desc = $conference->getConferenceDescription(); } $event_uid = $conference->getConferenceUID(); if( $event ) { $event_uid .= '-' . $event->getEventUID(); } if( $event ) { $event_stable_guid = $conference->getConferenceUID() . '-' . $event_ID . '@linuxdaytorino.org'; } else { $event_stable_guid = $conference->getConferenceUID() . '@linuxdaytorino.org'; } $event_location = null; // TODO: get this one (e.g. "Room A" or "Via Fasulla 123, Springfield") $event_geo_lat = null; $event_geo_lng = null; if( $conference->locationHasGeo() ) { $event_geo_lat = $conference->getLocationGeoLat(); $event_geo_lng = $conference->getLocationGeoLng(); } if( empty( $_GET['debug'] ) ) { header( 'Content-Type: text/calendar' ); header( sprintf( 'Content-Disposition: attachment; filename=%s.ics', $event_uid ) ); } else { header( 'Content-Type: text/plain' ); } echo get_ical( $event_stable_guid, $event_title, $event_start, $event_end, $event_url, $event_desc, $event_location, $event_geo_lat, $event_geo_lng ); function timestamp_to_ical( $timestamp ) { return date( 'Ymd\THis\Z', $timestamp ); } /** * Get an event (or conference as a single event) in iCal format. * * @param string $id Unique ID for this event * @param string $title Event title * @param int $start Start time (UNIX timestamp) * @param int $end End time (UNIX timestamp) * @param string $url Event URL * @param string $description Longer description of the event * @param string $location Name of event location, e.g. "Room A" * @param float $geo_lat Latitude of the location * @param float $geo_lon Longitude of the location * * @return string the event in iCal format */ function get_ical( $id, $title, $start, $end, $url = null, $description = null, $location = null, $geo_lat = null, $geo_lng = null ) { $rn = "\r\n"; $dtstart = timestamp_to_ical( $start->getTimestamp() ); $dtend = timestamp_to_ical( $end->getTimestamp() ); $dtstamp = timestamp_to_ical( time() ); $id = htmlspecialchars( $id ); $title = htmlspecialchars( $title ); if( !$description ) { $opt_description = ''; } else { $description = str_replace( "\n", " ", $description ); $description = strip_tags( $description ); $description = htmlspecialchars( $description ); $opt_description = "DESCRIPTION:$description"; } if( !$url ) { $opt_url = ''; } else { $opt_url = 'URL;VALUE=URI:' . htmlspecialchars( $url ); } if( !$geo_lat || !$geo_lng ) { $opt_geo = ''; } else { $opt_geo = "GEO:$geo_lat;$geo_lng"; } if( !$location ) { $opt_location = ''; } else { $location = htmlspecialchars( $location ); $opt_location = "LOCATION:$location"; } $ics = <<. class_exists('Event'); class_exists('Conference'); class_exists('Location'); class_exists('Room'); class_exists('Chapter'); class_exists('Track'); trait FullEventTrait { /** * Check if the Event has a permalink * * @return bool */ public function hasEventPermalink() { return $this->has( Conference::UID ) && $this->has( Event ::UID ) && $this->has( Chapter ::UID ); } - function getEventURL( $base = URL ) { - return $base . FullEvent::permalink( + /** + * Get the Event URL + */ + public function getEventURL( $absolute = false ) { + return FullEvent::permalink( $this->getConferenceUID(), $this->getEventUID(), - $this->getChapterUID() + $this->getChapterUID(), + $absolute ); } function forceEventPermalink() { $url = $this->getEventURL( ROOT ); if( $url !== $_SERVER['REQUEST_URI'] ) { http_redirect( $url ); } } function factoryNextFullEvent() { return $this->factoryFullEventInSameContext() ->where( sprintf( "event_start >= '%s'", esc_sql( $this->getEventEnd('Y-m-d H:i:s') ) ) ) ->orderBy('event_start'); } function factoryPreviousFullEvent() { return $this->factoryFullEventInSameContext() ->where( sprintf( "event_end <= '%s'", esc_sql( $this->getEventStart('Y-m-d H:i:s') ) ) ) ->orderBy('event_end DESC'); } /** * Get the edit URL for this FullEvent * * @param boolean $absolute Flag to require an absolute URL * @return string */ public function getFullEventEditURL( $absolute = false ) { return FullEvent::editURL( [ 'uid' => $this->getEventUID(), 'conference' => $this->getConferenceUID() ], $absolute ); } private function factoryFullEventInSameContext() { return FullEvent::factory() ->whereInt( 'event.conference_ID', $this->getConferenceID() ) ->whereInt( 'event.room_ID', $this->getRoomID() ); } } /** * An Event with all the bells and whistles */ class FullEvent extends Queried { use FullEventTrait; use EventTrait; use ConferenceTrait; use LocationTrait; use ChapterTrait; use RoomTrait; use TrackTrait; public function __construct() { $this->normalizeEvent(); $this->normalizeConference(); $this->normalizeChapter(); $this->normalizeRoom(); $this->normalizeTrack(); } /** * Query constructor * * @return Query */ public static function factory() { return Query::factory( __CLASS__ ) ->from( [ Event ::T, Conference::T, Room ::T, Track ::T, Chapter ::T, ] ) ->equals( Event::CONFERENCE_, Conference::ID_ ) ->equals( Event::ROOM_, Room ::ID_ ) ->equals( Event::TRACK_, Track ::ID_ ) ->equals( Event::CHAPTER_, Chapter ::ID_ ); } static function factoryByConference( $conference_ID ) { return self::factory() ->whereInt( Event::CONFERENCE_, $conference_ID ); } /** * @deprecate Use self::factoryFromConferenceAndUID() instead */ static function factoryByConferenceAndUID( $conference_ID, $event_uid ) { $event_uid = Event::sanitizeUID( $event_uid ); return self::factoryByConference( $conference_ID ) ->whereStr( Event::UID, $event_uid ); } /** * Factory from a Conference object and the Event UID * * @param object $conference * @param string $event_uid * @return Query */ public static function factoryFromConferenceAndEventUID( $conference, $event_uid ) { $event_uid = Event::sanitizeUID( $event_uid ); $conference_ID = $conference->getConferenceID(); return self::factoryByConference( $conference_ID ) ->whereStr( Event::UID, $event_uid ); } static function queryByConferenceAndUID( $conference_ID, $event_uid ) { return self::factoryByConferenceAndUID( $conference_ID, $event_uid ) ->queryRow(); } static function factoryByUser( $user_ID ) { return self::factory() ->from( EventUser::T ) ->equals( EventUser::EVENT_, Event::ID_ ) ->whereInt( EventUser::USER_, $user_ID ) ->orderBy( EventUser::ORDER ); } static function factoryByConferenceChapter( $conference_ID, $chapter_ID ) { return self::factoryByConference( $conference_ID ) ->whereInt( Event::CHAPTER_, $chapter_ID ); } /** * Get an absolute FullEvent permalink * * @param $conference_uid string Conference UID * @param $event_uid string Event UID * @param $chapter_uid string Chapter UID + * @param string $absolute Force an absolute URL + * @return string */ - public static function permalink( $conference_uid, $event_uid, $chapter_uid ) { - return sprintf( PERMALINK_EVENT, $conference_uid, $event_uid, $chapter_uid ) ; - + public static function permalink( $conference_uid, $event_uid, $chapter_uid, $absolute = false ) { + $url = sprintf( PERMALINK_EVENT, $conference_uid, $event_uid, $chapter_uid ) ; + return site_page( $url, $absolute ); } /** * Get the edit URL to a FullEvent * * @param array $args Arguments for the edit page * @param boolean $absolute Flag to require an absolute URL * @return string */ public static function editURL( $args, $absolute = false ) { $url = http_build_get_query( '/2016/event-edit.php', $args ); return site_page( $url, $absolute ); } } diff --git a/includes/load-post.php b/includes/load-post.php index 5400ff5..55176ea 100644 --- a/includes/load-post.php +++ b/includes/load-post.php @@ -1,110 +1,110 @@ . // Die if called directly defined('BOZ_PHP') or exit; // Custom Sessionuser class define('SESSIONUSER_CLASS', 'User'); define('INCLUDES', 'includes'); // Autoload classes spl_autoload_register( function($c) { $path = ABSPATH . __ . INCLUDES . __ . "class-$c.php"; if( is_file( $path ) ) { require $path; } } ); // One day I will push these 2 functions in Boz-PHP require ABSPATH . '/includes/functions.php'; // user permissions register_permissions( 'user', [] ); // admin permissions inherit_permissions( 'admin', 'user', [ 'add-event', 'edit-users', 'edit-events', ] ); define_default( 'LATEST_CONFERENCE_UID', '2019' ); define_default( 'CURRENT_CONFERENCE_UID', LATEST_CONFERENCE_UID ); define_default( 'CONTACT_PHONE_PREFIX', '+39' ); define_default( 'REPO', 'https://github.com/valerio-bozzolan/LinuxDay-Torino-website' ); define_default( 'LIBMARKDOWN_PATH', '/usr/share/php/markdown.php' ); define_default( 'JQUERY', '/javascript/jquery/jquery.min.js' ); define_default( 'LEAFLET_DIR', '/javascript/leaflet' ); define_default( 'NOINDEX', false ); // /{conference_uid}/ define_default( 'PERMALINK_CONFERENCE', '/%s/' ); // /{conference_uid}/{$chapter_uid}/{event_uid} -define_default( 'PERMALINK_EVENT', '/%1$s/%3$s/%2$s' ); +define_default( 'PERMALINK_EVENT', '%1$s/%3$s/%2$s' ); // /2016/{user_uid} define_default( 'PERMALINK_USER', '/%1$s/user/%2$s' ); define_default( 'FORCE_PERMALINK', 1 ); // timezone of database dates define_default( 'DEFAULT_TIMEZONE', 'Europe/Rome' ); register_js( 'jquery', JQUERY ); register_js( 'leaflet', LEAFLET_DIR . '/leaflet.js' ); register_css( 'leaflet', LEAFLET_DIR . '/leaflet.css' ); register_js('typed', ROOT . '/2017/static/typed/typed.min.js'); // GNU Gettext configuration define( 'GETTEXT_DOMAIN', 'linuxday' ); define( 'GETTEXT_DIRECTORY', ABSPATH . __ . 'l10n' ); define( 'GETTEXT_DEFAULT_ENCODE', 'utf8' ); // register languages register_language( 'en_US', ['en', 'en-us', 'en-en'], null, null, 'English' ); register_language( 'it_IT', ['it', 'it-it'], null, null, 'Italiano' ); register_default_language( 'it_IT' ); // apply the global timezone date_default_timezone_set( DEFAULT_TIMEZONE ); // apply a language if( isset( $_GET[ 'l' ] ) ) { // for this request only apply_language( $_GET[ 'l' ] ); } elseif( isset( $_POST[ 'l' ] ) ) { if( false !== apply_language( $_POST[ 'l' ] ) ) { // also for future requests setcookie( 'l', latest_language()->getCode() ); } } else { // when the cookie is empty is taken from browser language apply_language( @ $_COOKIE[ 'l' ] ); }